36. Valid Sudoku - LeetCode Solution


Array Hash Table Matrix

Python Code:

class Solution:
    def isValidSudoku(self, board: List[List[str]]) -> bool:
        
        a = [0, 3, 6, 9]
        b = [0, 3, 6, 9]
        
        
        for count in range(3):
            for count2 in range(3):
                arr = [-1] * 10
                for i in range(a[count], a[count+1]):
                    for j in range(b[count2], b[count2+1]):
                        if board[i][j] == ".":
                            continue
                        else:
                            if arr[int(board[i][j])] != -1:
                                
                                return False
                            else:
                                arr[int(board[i][j])] = 1
        
            
        for i in range(9):
            k = {}
            for j in range(9):
                if board[i][j] == ".":
                    continue
                if board[i][j] in k:
                    return False
                else:
                    k[board[i][j]] = 1
        for j in range(9):
            k = {}
            for i in range(9):
                if board[i][j] == ".":
                    continue
                if board[i][j] in k:
                    return False
                else:
                    k[board[i][j]] = 1
        return True
                    
            
            


Comments

Submit
0 Comments
More Questions

127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers